﻿/**
 * @author sminutoli
 * version 1.2
 * Por ahora lo mapea como me lo manda el muchacho, usando solo el new y el old, el VoiceMessage ya soporta un from y un date por las dudas por ahora lo harcodeo para el display
 * El from del message es un extId, será cuestión de la capa de presentación vincular eso con un contacto
 * Hay un setURL
 *  
 */
 
import com.dinmax.flash.central.extension.message.*
import com.dinmax.flash.central.extension.user.User
import com.dinmax.flash.central.extension.user.UserFactory
import com.dinmax.flash.utilities.xml.XMLUtils
import com.dinmax.flash.utilities.date.JavaDateParser

class VoiceMessageFactory {
	
	public static function getVoiceMessages(node:XMLNode):Array {
		//trace("VoiceMessageFactory.as | getVoiceMessages() "+node);
	
		var vMails:Array = new Array();
				
		for(var vm:XMLNode = node.firstChild; vm != null; vm=vm.nextSibling){
			if(vm.nodeType == 1){
				vMails.push(VoiceMessageFactory.getVoiceMessage(vm));
			};
		};
		
		return vMails;
	}
	
	public static function getVoiceMessage(node:XMLNode):VoiceMessage {
		//trace("VoiceMessageFactory.as | getVoiceMessage() "+node);
		var vMail:VoiceMessage = new VoiceMessage();
		vMail.setId(XMLUtils.getAttribute(node, "id"));
		vMail.setMessageURL(XMLUtils.getAttribute(node, "url"));
		vMail.setState(XMLUtils.getAttribute(node, "type"));
		vMail.setCallerid(XMLUtils.getAttribute(node, "callerid"));
		vMail.setFrom(Number(XMLUtils.getAttribute(node, "from")));
		vMail.setTime(JavaDateParser.convertDate(Number(XMLUtils.getAttribute(node, "date"))));
		
		return vMail;
	};
}